<?php

class Application_Model_Routes extends Zend_Db_Table_Abstract
{
    protected $_name = 'routes';
    //Получаем оставшееся время подписки
    public function getStatusTime($id){
        $this->_name = 'transactions';
        $select = $this->select()->from($this->_name)
                                 ->where('id_client = ?', intval($id));
        return $this->fetchRow($select);
    }
    
    public function updateTime($id, $data){
        $this->_name = 'status';
        $this->update($data)
            ->where('id_client = ?', intval($id));
    }
    
    public function addMarkers($data) {
        $this->_name = 'markers';
        $this->insert($data);
    }
    
    public function saveRoute($data) {
        $this->insert($data);
        return $this->getAdapter()->lastInsertId();
    }  
    
    public function saveCoordinate($data) {
        $this->_name = 'coordinates';
        $this->insert($data);
    }
    
    public function getSelectRoute($id) {
        $select = $this->select()->from($this->_name)
                                 ->from('id =?', intval($id));
        return $this->fetchRow($select);
    }
    
    public function getRouteCoordinate($id) {
        $this->_name = 'coordinates';
        $select = $this->select()->from($this->_name)
                                 ->where('id_route =?', intval($id));
        return $this->fetchAll($select)->toArray();
    }
    
    public function getSavedRoutes($id) {
        $select = $this->select()->from($this->_name)
                                 ->where('id_client =?', intval($id));
        return $this->fetchAll($select)->toArray();
    }
    
    public function deleteSelectRoute($id) {
        $this->delete('id ='.intval($id));
    }
    
    public function deleteSelectCoordinate($id) {
        $this->_name = 'coordinates';
        $this->delete('id_route ='.intval($id));
    }
}